package com.chefu;

import com.chefu.common.pojo.PageResult;
import com.chefu.evaluation.pojo.PartsOrderEval;
import com.chefu.evaluation.pojo.PartsProviderInfo;
import com.chefu.evaluation.pojo.ServiceOrderEval;
import com.chefu.evaluation.pojo.ServiceProviderInfo;
import com.chefu.evaluation.service.PartsOrderEvalService;
import com.chefu.evaluation.service.ServOrderEvalService;
import com.chefu.evaluation.vo.POSearchVO;
import com.chefu.evaluation.vo.SOSearchVO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class testEvaluation {
    @Autowired
    private PartsOrderEvalService partsOrderEvalService;
    @Autowired
    private ServOrderEvalService servOrderEvalService;
    @Autowired
    private MongoTemplate mongoTemplate;

    //配件评论
    @Test
    public void testSave() throws ParseException {
        PartsOrderEval partsOrderEval = new PartsOrderEval();
        partsOrderEval.setOrderId("1376949035973234688");
        partsOrderEval.setProviderId("1376949130777145344");
        partsOrderEval.setProviderName("海德汉");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = simpleDateFormat.parse("2021-02-25");
        partsOrderEval.setCreateTime(date);
        partsOrderEval.setCarOwnerId("1376949206748610560");
        partsOrderEval.setCarOwnerName("大狐狸");
        partsOrderEval.setScores(new Double[]{1.0, 1.0, 1.0});
        partsOrderEval.setContent("机油点不着，差评了");
        partsOrderEval.setImages(new String[]{"24546545.img", "63567454546.img"});
        partsOrderEval.setPartsItem("机油");
        partsOrderEval.setTotalFee(45.5);
        partsOrderEval.setState("0");
        mongoTemplate.save(partsOrderEval);
    }

    @Test
    public void testFindByPage() {
        POSearchVO poSearchVO = new POSearchVO();
        poSearchVO.setPartsProvider("丰");
        poSearchVO.setStartTime("2015-08-12");
        poSearchVO.setEndTime("2021-03-29");
        PageResult<PartsOrderEval> pageResult = partsOrderEvalService.findByPage(1, 4, poSearchVO);
        System.out.println("总条数为：" + pageResult.getTotal());
        System.out.println("总页数为：" + pageResult.getTotalPage());
        List<PartsOrderEval> contents = pageResult.getItems();
        for (PartsOrderEval content : contents) {
            System.out.println(content);
        }
    }

    //服务评价
    @Test
    public void testServSave() throws ParseException {
        ServiceOrderEval serviceOrderEval = new ServiceOrderEval();
        serviceOrderEval.setOrderId("1376967156595437568");
        serviceOrderEval.setProviderId("1376967253358129152");
        serviceOrderEval.setProviderName("恶霸修车店");
        serviceOrderEval.setServiceStatus("0");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = simpleDateFormat.parse("2015-10-13");
        serviceOrderEval.setCreateTime(date);
        serviceOrderEval.setCarOwnerId("1376967335251910656");
        serviceOrderEval.setCarOwnerName("二狗子");
        serviceOrderEval.setScores(new Double[]{1.0, 2.0, 3.0});
        serviceOrderEval.setContent("好家伙，把我车修炸了");
        serviceOrderEval.setImages(new String[]{"24546545.img", "63567454546.img"});
        serviceOrderEval.setServiceItem("补胎");
        serviceOrderEval.setTotalFee(142.0);
        serviceOrderEval.setState("0");
        mongoTemplate.save(serviceOrderEval);
    }

    @Test
    public void testServFindByPage() {
        SOSearchVO soSearchVO = new SOSearchVO();
        soSearchVO.setServiceStatus("0");
        soSearchVO.setStartTime("2014-08-12");
        soSearchVO.setEndTime("2021-03-29");
        PageResult<ServiceOrderEval> pageResult = servOrderEvalService.findByPage(1, 4, soSearchVO);
        System.out.println("总条数为：" + pageResult.getTotal());
        System.out.println("总页数为：" + pageResult.getTotalPage());
        List<ServiceOrderEval> contents = pageResult.getItems();
        for (ServiceOrderEval content : contents) {
            System.out.println(content);
        }
    }

    @Test
    public void testPartsProInfo() {
        PartsProviderInfo partsProviderInfo = new PartsProviderInfo();
        partsProviderInfo.setProviderId("1376948079898460160");
        partsProviderInfo.setProviderName("海德汉");
        partsProviderInfo.setProviderImage("54664546.png");
        mongoTemplate.save(partsProviderInfo);
    }

    @Test
    public void testServiceProviderInfo() {
        ServiceProviderInfo serviceProviderInfo = new ServiceProviderInfo();
        serviceProviderInfo.setProviderId("1376965509077127168");
        serviceProviderInfo.setProviderName("小拇指上地店");
        serviceProviderInfo.setProviderAddress("上地软件园东路");
        serviceProviderInfo.setProviderImage("xiaomuzhi.jpg");
        serviceProviderInfo.setContentNum("16");
        serviceProviderInfo.setScore(3.5);
        serviceProviderInfo.setProviderType("1");
        mongoTemplate.save(serviceProviderInfo);
    }
}
